package com.bl.student.manager.controller.pay;

import com.bl.student.manager.controller.BaseController;
import com.bl.student.common.ApiResponseBody;
import com.bl.student.service.biz.pay.PayService;
import com.bl.student.service.vo.pay.PayListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RequestMapping(value = {"/student/manager/pay"})
@Api(value = "支付相关api", description = "支付相关api")
@Log4j2
@RestController
public class PayController extends BaseController {
    @Autowired
    PayService payService;

    @ApiOperation(value = "支付记录，多条件筛选，筛选条件可以为空", notes = "支付记录，多条件筛选, 筛选条件可以为空")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "payer", value = "付款人id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "status", value = "状态", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "applyId", value = "申请id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每List页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_list"})
    public ApiResponseBody<PayListVo> payList(
            @RequestParam(value = "userId", required = false) String userId,
            @RequestParam(value = "payer", required = false) String payer,
            @RequestParam(value = "status", required = false) String status,
            @RequestParam(value = "applyId", required = false) String applyId,
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,
            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);

        PayListVo  payListVo = payService.getPayAndApplyListManager(userId,  payer, status, applyId, pageable);

        return ApiResponseBody.createSuccessBody(payListVo);
    }

}
